<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>固定定位</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }

    body{
      height: 2000px;
    }

    #header{
      /* 
        fixed: 固定定位，永远相对于浏览器的左上角
      */
      margin-top: 200px;
      width: 100%;
      height: 50px;
      background: #f00;
      /* position: fixed; */
      position: sticky;
      left: 0;
      top: 0;
      /* left/top/right/bottom这四个值，必须搭配position一起使用 */
    }
  </style>
</head>
<body>
  <div id="header">
    header
  </div>
</body>
</html>